/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Main Information      ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

var
	Line1 = list(6, 7, 8, 9, 10)
	Line2 = list(1, 2, 3, 4, 5)
	Line3 = list(11, 12, 13, 14, 15)
	Line4 = list(1, 7, 13, 9, 5)
	Line5 = list(11, 7, 3, 9, 15)
	Line6 = list(6, 2, 3, 4, 10)
	Line7 = list(6, 12, 13, 14, 10)
	Line8 = list(1, 2, 8, 14, 15)
	Line9 = list(11, 12, 8, 4, 5)
	Line10 = list(6, 12, 8, 4, 10)
	Line11 = list(6, 2, 8, 14, 10)
	Line12 = list(1, 7, 8, 9, 5)
	Line13 = list(11, 7, 8, 9, 15)
	Line14 = list(1, 7, 3, 9, 5)
	Line15 = list(11, 7, 13, 9, 15)
	Line16 = list(6, 7, 3, 9, 10)
	Line17 = list(6, 7, 13, 9, 10)
	Line18 = list(1, 2, 13, 4, 5)
	Line19 = list(11, 12, 3, 14, 13)
	Line20 = list(1, 12, 13, 14, 5)
	Line21 = list(11, 2, 3, 4, 15)
	Line22 = list(6, 12, 3, 14, 10)
	Line23 = list(6, 2, 13, 4, 10)
	Line24 = list(1, 12, 3, 14, 5)
	Line25 = list(11, 2, 13, 4, 15)

	Lines = list(Line1, Line2, Line3, Line4, Line5, Line6, Line7, Line8, Line9, Line10, Line11, Line12, Line13, Line14, Line15, Line16, Line17, Line18, Line19, Line20, Line21, Line22, Line23, Line24, Line25)

client/var
	// Machine info
	Video_Bet = 1
	Video_MBet = 60
	Video_Lines = 1
	Video_MLines = 25

	InSpin = FALSE

	// After Spin Calculations
	Video_LineWins = 0
	Video_LineCount = 1
	Video_Winnings = 0
	Video_FreeWinnings = 0

	// Slot Fundamentals
	reel[15]
	bank1 = list(2,3,4,5,8,15,20,30,100)
	bank2 = list(8,12,16,20,30,60,80,120,1000)
	bank3 = list(25,30,40,50,80,150,250,500,10000)



/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Machine Functions     ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

client/verb

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///     Bet Functions        ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

	VideoBetIncrease()
		set hidden = 1
		if(AutoSpin == TRUE) AutoSpin = FALSE; winset(src,"Games_VideoSlots.button15","text=\"Auto Spin\"")
		if(InSpin) return
		if(Video_Bet < Video_MBet) Video_Bet++
		Video_Main()

	VideoBetDecrease()
		set hidden = 1
		if(AutoSpin == TRUE) AutoSpin = FALSE; winset(src,"Games_VideoSlots.button15","text=\"Auto Spin\"")
		if(InSpin) return
		if(Video_Bet > 1) Video_Bet--
		Video_Main()

	VideoBetOne()
		set hidden = 1
		if(AutoSpin == TRUE) AutoSpin = FALSE; winset(src,"Games_VideoSlots.button15","text=\"Auto Spin\"")
		if(InSpin) return
		Video_Bet = 1
		Video_Main()

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Line Functions        ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

	VideoLineIncrease()
		set hidden = 1
		if(AutoSpin == TRUE) AutoSpin = FALSE; winset(src,"Games_VideoSlots.button15","text=\"Auto Spin\"")
		if(InSpin) return
		if(Video_Lines < Video_MLines) Video_Lines++
		Video_Main()

	VideoLineDecrease()
		set hidden = 1
		if(AutoSpin == TRUE) AutoSpin = FALSE; winset(src,"Games_VideoSlots.button15","text=\"Auto Spin\"")
		if(InSpin) return
		if(Video_Lines > 1) Video_Lines--
		Video_Main()

	VideoLinesOne()
		set hidden = 1
		if(AutoSpin == TRUE) AutoSpin = FALSE; winset(src,"Games_VideoSlots.button15","text=\"Auto Spin\"")
		if(InSpin) return
		Video_Lines = 1
		Video_Main()

////////////////////////////////

	VideoBetMax()
		set hidden = 1
		if(AutoSpin == TRUE) AutoSpin = FALSE; winset(src,"Games_VideoSlots.button15","text=\"Auto Spin\"")
		if(InSpin) return
		Video_Lines = Video_MLines
		Video_Bet = Video_MBet
		Video_Main()

/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Game Buttons          ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

	VideoPayButton()
		set hidden = 1
		GamesLoadVideoSlotInfo()

	VideoSpin()
		set hidden = 1
		spawn() Video_Spin()

	VideoAutoSpin()
		set hidden = 1
		if(AutoSpin == TRUE)
			AutoSpin = FALSE
			winset(src,"Games_VideoSlots.button15","text=\"Auto Spin\"")
		else
			AutoSpin = TRUE
			winset(src,"Games_VideoSlots.button15","text=\"Stop Spin\"")

		while(AutoSpin == TRUE)
			if(!hasFunds())
				AutoSpin = FALSE
				winset(src,"Games_VideoSlots.button15","text=\"Auto Spin\"")
			else if(FreeSpin == 0)
				Video_Spin()
				sleep(5)
			else
				sleep(5)


/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
///    Game Functions        ///
*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/


client/proc

	VideoInit()
		Video_Bet = 1
		Video_Lines = 1
		Video_Main()

	//returns if you have enough money to wager
	hasFunds()
		if(returnWager() <= Credits) return TRUE
		else return FALSE

	returnWager()
		return Video_Bet*Video_Lines

	//Initialize a machine spin.
	Video_Spin()
		if(!InSpin)
			InSpin = TRUE

			Video_Winnings = 0
			Video_FreeWinnings = 0
			Video_LineWins = 0

			LoadCasino()
			Video_Main()

			if(FreeSpin != 0)
				var/TempWin = 0

				while(FreeSpin > 0)
					Video_SetReels()

					TotalSpins++
					FreeSpin--

					TempWin = Video_Winnings

					if(TempWin != 0)
						for(var/i = 1; i<=3; i++)
							Video_FreeWinnings += Video_Winnings
							Video_Main()
							sleep(3)

					Video_Winnings = 0
					SaveCasino()
					sleep(3)
					Video_Main()

				Video_Winnings = Video_FreeWinnings


			else
				if(hasFunds())
					Credits-=returnWager()
					TotalWager+=returnWager()

					Video_Main()

					Video_SetReels()

					TotalSpins++

			Credits += Video_Winnings
			TotalWon += Video_Winnings


			SaveCasino()
			Video_Main()
			if(AutoSpin) sleep(5)
			InSpin = FALSE
			spawn() src.updateProfiles()
			if(FreeSpin > 0) spawn(2) Video_Spin()

		else
			return


	//Main loop for the machine.
	Video_Main()
		UpdateCredits()
		winset(src,"Games_VideoSlots.VideoCoins","text=\"[Video_Bet]\"")
		winset(src,"Games_VideoSlots.VideoLines","text=\"[Video_Lines]\"")

		if(FreeSpin > 0)
			winset(src,"Games_VideoSlots.VideoWinAmount","text=\"[Video_FreeWinnings]\"")
		else
			winset(src,"Games_VideoSlots.VideoWinAmount","text=\"[Video_Winnings]\"")
		winset(src,"Games_VideoSlots.VideoBet","text=\"[Video_Bet*Video_Lines]\"")
		winset(src,"Games_VideoSlots.freespins","text=\"[FreeSpin]\"")

		winset(src,"Games_VideoSlots.VideoWinLines","text=\"[num2text(Video_LineWins)]\"")

	//returns the color of the symbol bank
	Video_GetColor(var/n as num, var/x)
		if(x)
			if(n == 1) return VideoSlots_Symbol1w
			else if(n == 2) return VideoSlots_Symbol2w
			else if(n == 3) return VideoSlots_Symbol3w
			else if(n == 4) return VideoSlots_Symbol4w
			else if(n == 5) return VideoSlots_Symbol5w
			else if(n == 6) return VideoSlots_Symbol6w
			else if(n == 7) return VideoSlots_Symbol7w
			else if(n == 8) return VideoSlots_Symbol8w
			else if(n == 9) return VideoSlots_Wildw
			else if(n == 10) return VideoSlots_Scatterw
		else
			if(n == 1) return VideoSlots_Symbol1
			else if(n == 2) return VideoSlots_Symbol2
			else if(n == 3) return VideoSlots_Symbol3
			else if(n == 4) return VideoSlots_Symbol4
			else if(n == 5) return VideoSlots_Symbol5
			else if(n == 6) return VideoSlots_Symbol6
			else if(n == 7) return VideoSlots_Symbol7
			else if(n == 8) return VideoSlots_Symbol8
			else if(n == 9) return VideoSlots_Wild
			else if(n == 10) return VideoSlots_Scatter

	// Returns a number between 1 - 9
	// This is used for the RTP, do not change
	Video_ReturnSymbol()
		if(rand(1,35) == 1)
			return 10
		else
			return  pick(
				prob(43); 1,
				prob(35); 2,
				prob(29); 3,
				prob(25); 4,
				prob(22); 5,
				prob(18); 6,
				prob(15); 7,
				prob(13); 8,
				prob(11); 9,
			)


	// Loops through the 15 reel spots, and gathers symbols for them
	Video_SetReels()

		for(var/count = 1; count<=5; count++)
			reel[count] = Video_ReturnSymbol()
			reel[count+5] = Video_ReturnSymbol()
			reel[count+10] = Video_ReturnSymbol()

			while(reel[count+5] == reel[count])
				reel[count+5] = Video_ReturnSymbol()

			while(reel[count+10] == reel[count] || reel[count+10] == reel[count+5])
				reel[count+10] = Video_ReturnSymbol()

			var/text1 = reel[count]
			var/text2 = reel[count+5]
			var/text3 = reel[count+10]

			if(text1 == 10) text1="S"
			if(text1 == 9) text1="W"
			if(text2 == 10) text2="S"
			if(text2 == 9) text2="W"
			if(text3 == 10) text3="S"
			if(text3 == 9) text3="W"

			winset(src,"Games_VideoSlots.reel_[count]","background-color=\"[Video_GetColor(reel[count])]\";text=\"[text1]\"")
			winset(src,"Games_VideoSlots.reel_[count+5]","background-color=\"[Video_GetColor(reel[count+5])]\";text=\"[text2]\"")
			winset(src,"Games_VideoSlots.reel_[count+10]","background-color=\"[Video_GetColor(reel[count+10])]\";text=\"[text3]\"")

			sleep(1)
		Video_CheckLines(Video_Lines)


	// After the spin is finished, check each line for possible wins
	Video_CheckLines(var/LinesPlayed as num)

		for(var/i = 1; i<=LinesPlayed; i++)
			var/win = Video_CheckLine(Lines[i])
			if(win)
				Video_Winnings += win
				Video_Main()

		var
			free = 0
			spots = list()

		for(var/i = 1; i<=15; i++)
			if(reel[i] == 10)
				spots += i
				free++

		if(free == 3)
			FreeSpin += 10
			Video_BlinkLine(spots, 3)
		else if(free == 4)
			FreeSpin += 15
			Video_BlinkLine(spots, 4)
		else if(free == 5)
			FreeSpin += 20
			Video_BlinkLine(spots, 5)

	Video_CheckLine(var/reels)
		var
			amount = 0
			wild = FALSE
			symbol = reel[reels[1]]

		if(reel[reels[1]] == 9 && reel[reels[2]] != 9)
			symbol = reel[reels[2]]
		else if(reel[reels[2]] == 9 && reel[reels[3]] != 9)
			symbol = reel[reels[3]]
		else if(reel[reels[1]] == 9 && reel[reels[2]] == 9 && reel[reels[3]] == 9)
			if(reel[reels[4]] >= 6)
				symbol = reel[reels[4]]
			else if(reel[reels[4]] >= 5 && (reel[reels[5]] == reel[reels[4]] || reel[reels[5]] == 9))
				symbol = reel[reels[4]]

		if(symbol == 10) return

		for(var/i = 1; i<=5; i++)
			if(reel[reels[i]] == symbol)
				amount++
			else if(reel[reels[i]] == 9)
				amount++
				wild = TRUE
			else
				break


		if(amount == 3)
			amount = bank1[symbol] * Video_Bet
			Video_BlinkLine(reels, 3)

		else if(amount == 4)
			amount = bank2[symbol] * Video_Bet
			Video_BlinkLine(reels, 4)

		else if(amount == 5)
			amount = bank3[symbol] * Video_Bet
			Video_BlinkLine(reels, 5)

		else
			return 0

		if(wild && symbol!=9) amount*=2

		if(amount > 0)
			Video_LineWins++

		return amount

	Video_BlinkLine(var/reels, var/count)
		for(var/i = 1; i<=count; i++)
			winset(src,"Games_VideoSlots.reel_[reels[i]]","background-color=\"[Video_GetColor(reel[reels[i]],1)]\"")
			sleep(1)
		for(var/i = 1; i<=count; i++)
			winset(src,"Games_VideoSlots.reel_[reels[i]]","background-color=\"[Video_GetColor(reel[reels[i]])]\"")
			sleep(1)

		sleep(1)

		for(var/i = 1; i<=count; i++)
			winset(src,"Games_VideoSlots.reel_[reels[i]]","background-color=\"[Video_GetColor(reel[reels[i]],1)]\"")